<template>
	<view>
		<view class="item">
			<view class="item-left">
				<view class="name">
					姓名
				</view>
			</view>
			<view class="item-right">
				<view class="input">
					<input type="text" v-model="name" placeholder="请填写用户姓名" />
				</view>
			</view>
		</view>
		<view class="item">
			<view class="item-left">
				<view class="name">
					手机号
				</view>
			</view>
			<view class="item-right">
				<view class="input">
					<input type="text" v-model="tel" placeholder="请填写手机号" />
				</view>
			</view>
		</view>
		<view class="item">
			<view class="item-left">
				<view class="name">
					省市区
				</view>
			</view>
			<view class="item-right" @click="ssq">
				<view class="input">
					<text style="padding-right: 20rpx;font-size: 32rpx;"
						:style="address =='请选择省市区'?'color:#818181':''">{{ address }}</text>
				</view>
			</view>
		</view>
		<view class="item">
			<view class="item-left">
				<view class="name">
					详细地址
				</view>
			</view>
			<view class="item-right">
				<view class="input">
					<input type="text" v-model="xiang" placeholder="请填写详细地址" />
				</view>
			</view>
		</view>
		<view class="item">
			<view class="item-left">
				<view class="name">
					设为默认
				</view>
			</view>
			<view class="item-right">
				<view class="input">
					<u-switch @change="changeMO" v-model="mo" activeColor="#ef5350"></u-switch>
				</view>
			</view>
		</view>
		<view class="footer">
			<view class="footer-btn" @tap="add">
				确认新增
			</view>
		</view>
		<gui-area-picker ref="graceAddressPicker1" @confirm="confirm1" :level="3" cancelText="关闭"></gui-area-picker>
	</view>
</template>

<script>
	import tool from '../../utils/tool.js'
	export default {
		data() {
			return {
				tool: tool,
				mo: false,
				name: '',
				tel: '',
				sheng: '',
				shi: '',
				qu: '',
				xiang: '',
				address: '请选择省市区',
				mos: 'fei',
				value1: '',
			}
		},
		methods: {
			ssq() {
				console.log('123')
				this.open1()
			},
			open1: function() {
				this.$refs.graceAddressPicker1.open();
			},
			confirm1: function(e) {
				// 返回选中城市的编号及文本信息
				console.log(e);
				this.address = e.names[0] + '-' + e.names[1] + '-' + e.names[2];
				this.sheng = e.names[0]
				this.shi = e.names[1]
				this.qu = e.names[2]
			},
			changeMO(e) {
				if (e) {
					this.mos = 'mo'
				} else {
					this.mos = 'fei'
				}
			},
			add() {
				if (!this.name || !this.tel || !this.sheng || !this.shi || !this.qu || !this.xiang) {
					uni.showToast({
						title: "请填写相关信息",
						icon: 'none'
					})
					return
				}
				if (!this.tool.isValidPhoneNumber(this.tel)) {
					uni.showToast({
						title: "手机号格式不正确",
						icon: 'none'
					})
					return
				}
				this.$http.Post('address/add', {
					sheng: this.sheng,
					shi: this.shi,
					qu: this.qu,
					name: this.name,
					tel: this.tel,
					xiang: this.xiang,
					mo: this.mos
				}, (result) => {
					uni.showToast({
						title: '添加成功',
						icon: 'success'
					})
					setTimeout(res => {
						uni.navigateBack()
					}, 500)
				})
			}
		}
	}
</script>

<style>
	.item {
		width: 94%;
		margin: 20rpx auto;
		background-color: #fff;
		height: 100rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		border-radius: 8rpx;
	}

	.name {
		padding-left: 20rpx;
	}

	.input>input {
		text-align: right;
		padding-right: 20rpx;
	}

	.item-left {
		font-size: 28rpx;
		color: #3c3c3c;
	}

	.item-right {
		font-size: 28rpx;
	}

	.footer {
		position: fixed;
		bottom: 80rpx;
		height: 100rpx;
		width: 94%;
		margin-left: 3%;
	}

	.footer-btn {
		color: #fff;
		font-size: 28rpx;
		background-color: #ef5350;
		width: 100%;
		height: 100%;
		display: flex;
		justify-content: center;
		align-items: center;
		border-radius: 999rpx;
	}
</style>